/*
 * EnterOrder.java
 *
 * Created on __DATE__, __TIME__
 */

package com.DreamTeam.ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.DreamTeam.factory.DaoFactory;
import com.DreamTeam.po.OrderMaster;

/**
 *
 * @author  __USER__
 */
public class EnterOrder extends javax.swing.JDialog {

	/** Creates new form EnterOrder */
	public EnterOrder(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
		setResizable(false);
		setLocationRelativeTo(null);
		this.parent = (OrderSubsystem) parent;

	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jPanel1 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		tf_OrderNo = new javax.swing.JTextField();
		jLabel2 = new javax.swing.JLabel();
		tf_CustomerNo = new javax.swing.JTextField();
		jLabel3 = new javax.swing.JLabel();
		tf_EmployeeNo = new javax.swing.JTextField();
		jLabel4 = new javax.swing.JLabel();
		tf_invoiceNo = new javax.swing.JTextField();
		jLabel5 = new javax.swing.JLabel();
		btn_add = new javax.swing.JButton();
		btn_back = new javax.swing.JButton();
		tf_year = new javax.swing.JTextField();
		jLabel8 = new javax.swing.JLabel();
		tf_month = new javax.swing.JTextField();
		jLabel9 = new javax.swing.JLabel();
		tf_day = new javax.swing.JTextField();
		jLabel10 = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jLabel1.setText("\u8ba2\u5355\u53f7\uff1a");

		jLabel2.setText("\u5ba2\u6237\u53f7\uff1a");

		jLabel3.setText("\u5458\u5de5\u53f7\uff1a");

		jLabel4.setText("\u53d1\u7968\u53f7\uff1a");

		jLabel5.setText("\u65f6\u95f4\uff1a");

		btn_add.setText("\u6dfb\u52a0");
		btn_add.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_addActionPerformed(evt);
			}
		});

		btn_back.setText("\u540e\u9000");
		btn_back.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_backActionPerformed(evt);
			}
		});

		jLabel8.setText("\u5e74");

		jLabel9.setText("\u6708");

		jLabel10.setText("\u65e5");

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
				jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout
				.setHorizontalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addGap(23, 23, 23)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																jPanel1Layout
																		.createSequentialGroup()
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								jLabel1)
																						.addComponent(
																								jLabel2)
																						.addComponent(
																								jLabel3)
																						.addComponent(
																								jLabel4))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								tf_invoiceNo,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								231,
																								Short.MAX_VALUE)
																						.addComponent(
																								tf_EmployeeNo,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								231,
																								Short.MAX_VALUE)
																						.addComponent(
																								tf_CustomerNo,
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								231,
																								Short.MAX_VALUE)
																						.addComponent(
																								tf_OrderNo,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								231,
																								Short.MAX_VALUE)))
														.addGroup(
																jPanel1Layout
																		.createSequentialGroup()
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								btn_add)
																						.addGroup(
																								jPanel1Layout
																										.createSequentialGroup()
																										.addComponent(
																												jLabel5)
																										.addGap(18,
																												18,
																												18)
																										.addComponent(
																												tf_year,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												55,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				jPanel1Layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addGroup(
																								jPanel1Layout
																										.createSequentialGroup()
																										.addComponent(
																												jLabel8)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												tf_month,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												40,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												jLabel9)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												tf_day,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												38,
																												javax.swing.GroupLayout.PREFERRED_SIZE))
																						.addComponent(
																								btn_back))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jLabel10,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				48,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		jPanel1Layout
				.setVerticalGroup(jPanel1Layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								jPanel1Layout
										.createSequentialGroup()
										.addGap(28, 28, 28)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel1)
														.addComponent(
																tf_OrderNo,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(26, 26, 26)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
														.addComponent(
																tf_CustomerNo,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(26, 26, 26)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel3)
														.addComponent(
																tf_EmployeeNo,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(26, 26, 26)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel4)
														.addComponent(
																tf_invoiceNo,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(30, 30, 30)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel5)
														.addComponent(jLabel8)
														.addComponent(
																tf_year,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																tf_month,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel9)
														.addComponent(
																tf_day,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel10))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												38, Short.MAX_VALUE)
										.addGroup(
												jPanel1Layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(btn_add)
														.addComponent(btn_back))));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jPanel1,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jPanel1,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE,
								Short.MAX_VALUE).addContainerGap()));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void btn_addActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		String orderNo = tf_OrderNo.getText();
		String customerNo = tf_CustomerNo.getText();
		String employeeNo = tf_EmployeeNo.getText();
		String invoiceNo = tf_invoiceNo.getText();
		String year = tf_year.getText();
		String day = tf_day.getText();
		String month = tf_month.getText();

		
		Date date = null;
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = sf.parse(year + "-" + month + "-" + day);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Double sum=new Double(0);
		OrderMaster orderMaster = new OrderMaster();
		orderMaster.setOrderNo(orderNo);
		orderMaster.setCustomerNo(customerNo);
		orderMaster.setEmployeeNo(employeeNo);
		orderMaster.setInvoiceNo(invoiceNo);
		orderMaster.setOrderDate(date);
		orderMaster.setOrderSum(sum);

		Object[] ele = { orderNo, customerNo, employeeNo, date, sum, invoiceNo };
		DaoFactory.getOrderMasterDaoImplInstance().doAdd(orderMaster);
		parent.addElement(ele);
		
		
		
		
	}

	//GEN-END:initComponents

	private void btn_backActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		this.dispose();

	}

	public void setValue(OrderMaster orderMaster) {
		tf_OrderNo.setText(orderMaster.getOrderNo());
		tf_OrderNo.setEditable(false);
		tf_CustomerNo.setText(orderMaster.getCustomerNo());
		tf_EmployeeNo.setText(orderMaster.getEmployeeNo());
		String date = orderMaster.getOrderDate().toString();
		String[] temp = date.split("-");
		tf_year.setText(temp[0]);
		tf_month.setText(temp[1]);
		tf_day.setText(temp[2]);
		tf_invoiceNo.setText(orderMaster.getInvoiceNo());
		

	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				EnterOrder dialog = new EnterOrder(new javax.swing.JFrame(),
						true);
				dialog.addWindowListener(new java.awt.event.WindowAdapter() {
					public void windowClosing(java.awt.event.WindowEvent e) {
						System.exit(0);
					}
				});
				dialog.setVisible(true);

			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btn_add;
	private javax.swing.JButton btn_back;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel10;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JLabel jLabel5;
	private javax.swing.JLabel jLabel8;
	private javax.swing.JLabel jLabel9;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JTextField tf_CustomerNo;
	private javax.swing.JTextField tf_EmployeeNo;
	private javax.swing.JTextField tf_OrderNo;
	private javax.swing.JTextField tf_day;
	private javax.swing.JTextField tf_invoiceNo;
	private javax.swing.JTextField tf_month;
	private javax.swing.JTextField tf_year;
	private OrderSubsystem parent;
	// End of variables declaration//GEN-END:variables

}